﻿using AiXiu.BLL;
using AiXiu.Common;
using AiXiu.IBLL;
using AiXiu.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AiXiu.Web
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnRegister_Click(object sender, EventArgs e)
        {
            //验证控件
            if (Page.IsValid)
            {
                //输入的验证码和session比较
                if (Session["yzm"] != null)
                {
                    string code = txtCaptcha.Text.Trim();
                    if (!string.IsNullOrWhiteSpace(code))
                    {
                        if (Session["yzm"].ToString().Equals(code))
                        {
                            IUserManager userManager = new UserManager();
                            TBLogins tBLogins = new TBLogins
                            {
                                Password = txtPassword.Text,
                                MobileNumber = txtMobileNumber.Text,
                                UserName = txtUserName.Text
                            };
                            OperResult operResult = userManager.Reg(tBLogins);
                            if (operResult.StatusCode == StatusCode.Succeed)
                            {
                                PageExtensions.AlertAndRedirect(this, "reg", operResult.Message, "Land.aspx");
                            }
                            else
                            {
                                PageExtensions.Alert(this, "regError", operResult.Message);
                            }
                        }
                        else
                        {
                            PageExtensions.Alert(this, "regError", "验证码错误");
                        }
                    }else{
                        PageExtensions.Alert(this, "regError", "验证码不能为空");
                    }
                }
            }else{
                PageExtensions.Alert(this, "regError", "验证信息不能为空");
            }
        }
    }
}